const {
  http
} = require("../../../../utils/apiutils");

import {getoAuthToken,queryYezz} from '../../../../utils/bdutils'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    username: "",
    info: {
      lng: "",
      lat: "",
    },
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  onclickAdress: function () {
    wx.navigateTo({
      url: '/pages/me/pages/address/address?type=2',
    })
  },
  getComInfo: function () {
    var data = {

    }
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    http.getComInfo(data,
      function (res) {
        wx.hideLoading()
        console.log("-----已完成任务列表---", res);
        if (res.success) {
          if (res.data && res.data.id) {
            that.setData({
              info: res.data
            })
            console.log(that.data.info)
          }

        } else {
          wx.showToast({
            title: res.message,
            icon: "none",
          })
        }
      },
      function (err) {
        wx.hideLoading()
      })

  },
  onclcikSure: function (e) {
    console.log("-----", this.data.info)
    if (this.data.info.id) {
      http.companyOperation(this.data.info,
        function (res) {
          wx.hideLoading()
          wx.showModal({
            title: "提示",
            content: "保存成功",
            showCancel: false,
            success: function () {
              wx.navigateBack({
                delta: 1,
              })
            },
          })
          console.log("-----修改成功---", res);
        },
        function (err) {
          wx.hideLoading()
        })
    } else {
      this.data.info.id = getApp().globalData.share_id||''
      console.log('公司信息添加',getApp().globalData.share_id||'')
      http.addCompanyOperation(this.data.info,
        function (res) {
          wx.hideLoading()
          wx.showModal({
            title: "提示",
            content: "保存成功",
            showCancel: false,
            success: function () {
              wx.reLaunch({
                url: '/pages/index/index',
              })
            },
          })
          console.log("-----修改成功---", res);
        },
        function (err) {
          wx.hideLoading()
        })

    }

  },
  factoryName: function (e) {
    this.data.info.factoryName = e.detail;
  },
  business: function (e) {
    this.data.info.business = e.detail;
  },
  factoryId: function (e) {
    this.data.info.factoryId = e.detail;
  },
  creditCode: function (e) {
    this.data.info.creditCode = e.detail;
  },
  legalName: function (e) {
    this.data.info.legalName = e.detail;
  },
  accountBank: function (e) {
    this.data.info.accountBank = e.detail;
  },
  accountName: function (e) {
    this.data.info.accountName = e.detail;
  },
  factoryBankId: function (e) {
    this.data.info.bankId = e.detail;
  },
  legalPhone: function (e) {
    this.data.info.contactPhone = e.detail;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (getApp().globalData.exist) {
      this.getComInfo()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  choose(){
    getoAuthToken();
    wx.chooseImage({
      count: 1,
      success(res){
        var base64 = 'data:image/jpg;base64,' + wx.getFileSystemManager().readFileSync(res.tempFilePaths[0], "base64");
        let params={
          image:base64
        }
        queryYezz(params,(res1)=>{console.log(res1)},err=>{
          console.log(err)
        })
      }
    })
  }
})